package org.neframework.test.model;

import java.util.HashMap;
import java.util.Map;

public class TableModel {

	private String tableName;
	private TableColumnModel id;
	private Map<String, TableColumnModel> columns = new HashMap<String, TableColumnModel>();

	// 2、如果发现主键设置错了,应该是id是主键,但如今表里已经有好多数据了,不能删除表再重建了，仅仅能在这基础上改动表结构。
	// 先删除主键
	// alter table table_test drop primary key;
	// 然后再增加主键
	// alter table table_test add primary key(id);
	// 注:在增加主键之前,必须先把反复的id删除掉。

	// =========== get / set ()====================
	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public TableColumnModel getId() {
		return id;
	}

	public void setId(TableColumnModel id) {
		this.id = id;
	}

	public Map<String, TableColumnModel> getColumns() {
		return columns;
	}

	public void setColumns(Map<String, TableColumnModel> columns) {
		this.columns = columns;
	}

	@Override
	public String toString() {
		return "TableModel [tableName=" + tableName + ", id=" + id + ", columns=" + columns + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((columns == null) ? 0 : columns.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((tableName == null) ? 0 : tableName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TableModel other = (TableModel) obj;
		if (columns == null) {
			if (other.columns != null)
				return false;
		} else if (!columns.equals(other.columns))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (tableName == null) {
			if (other.tableName != null)
				return false;
		} else if (!tableName.equals(other.tableName))
			return false;
		return true;
	}

}
